package com.mf.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * webconfig
 *
 * @author: Jiang Runqing
 * @date: 2018-10-23 23:55
 */
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {


    @Value("${file.filePath}")
    private String filePath;

    String urlFilePath;
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //其中data表示访问的前缀。"file:/data/"是文件真实的存储路径
        urlFilePath = filePath;
        if(-1!=filePath.indexOf(":")){
            urlFilePath = filePath.substring(filePath.lastIndexOf(":")+1);
        }
        registry.addResourceHandler(urlFilePath+"**").addResourceLocations("file:"+filePath);
    }
}
